C#: Refactor- and rename operation expressions.#21909
Conversation
d13e5e8 to
0834f65
Compare
|
@aschackmull : We discussed a while back that we should restructure the hierarchy of operation expressions (streamlining it with other languages) such that |
…some other minor changes).
…e other minor changes).
…e other minor changes).
|
LGTM! |
0834f65 to
346d140
Compare
There was a problem hiding this comment.
Pull request overview
This PR restructures C# “operation” expression types so that the *Operation QL classes also cover compound assignment forms (for example, treating a += b as a BinaryArithmeticOperation). It updates the C# dbscheme categories, refactors/renames the relevant expression class hierarchy, and adjusts affected queries/tests and upgrade/downgrade metadata accordingly.
Changes:
- Expand arithmetic/bitwise/logical operation classifications to include compound assignments via new/renamed operation groupings.
- Refactor and deprecate older operation-related QL modules/types (introducing newer
*Expr/*Operationnaming and aliases). - Update tests, change notes, and add dbscheme upgrade/downgrade scaffolding for the refactor.
Show a summary per file
| File | Description |
|---|---|
| csharp/ql/test/library-tests/csharp11/operators.ql | Updates library-test query predicates to use the renamed assignment bitwise expression type. |
| csharp/ql/test/library-tests/csharp11/operators.expected | Adjusts expected results to reflect compound assignments now matching bitwise operation queries. |
| csharp/ql/lib/upgrades/3cabc77473cbbda95edebafea345c2e3fdfa12d9/upgrade.properties | Adds upgrade metadata for the operations refactor. |
| csharp/ql/lib/upgrades/3cabc77473cbbda95edebafea345c2e3fdfa12d9/semmlecode.csharp.dbscheme | Adds upgrade dbscheme snapshot/scaffolding. |
| csharp/ql/lib/upgrades/3cabc77473cbbda95edebafea345c2e3fdfa12d9/old.dbscheme | Adds “old” dbscheme snapshot for upgrade comparisons. |
| csharp/ql/lib/semmlecode.csharp.dbscheme | Renames/restructures operation-related dbscheme unions to include assignment forms. |
| csharp/ql/lib/semmle/code/csharp/exprs/Operation.qll | Deprecates the prior “operations that also have compound assignment forms” module. |
| csharp/ql/lib/semmle/code/csharp/exprs/LogicalOperation.qll | Updates logical operation taxonomy and introduces a shared null-coalescing operation base. |
| csharp/ql/lib/semmle/code/csharp/exprs/Expr.qll | Switches Operation/UnaryOperation/BinaryOperation/TernaryOperation to the new dbscheme categories. |
| csharp/ql/lib/semmle/code/csharp/exprs/Call.qll | Updates compound-assignment operator call modeling to extend the renamed assignment-call class. |
| csharp/ql/lib/semmle/code/csharp/exprs/BitwiseOperation.qll | Refactors bitwise operation classes to distinguish operation-vs-expression and include assignment forms. |
| csharp/ql/lib/semmle/code/csharp/exprs/Assignment.qll | Renames/restructures assignment-call and assignment operation class hierarchy and adds deprecation aliases. |
| csharp/ql/lib/semmle/code/csharp/exprs/ArithmeticOperation.qll | Refactors arithmetic operation classes to include assignment forms under operation categories. |
| csharp/ql/lib/semmle/code/csharp/dispatch/Dispatch.qll | Updates dispatch modeling to the renamed assignment arithmetic type. |
| csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll | Aligns guard logic with updated arithmetic operation coverage. |
| csharp/ql/lib/semmle/code/csharp/Assignable.qll | Updates assignable-definition logic to the renamed assignment-call class. |
| csharp/ql/lib/experimental/code/csharp/Cryptography/NonCryptographicHashes.qll | Updates experimental query logic to use the renamed/refactored operation/expression classes. |
| csharp/ql/lib/change-notes/2026-06-12-restructure-operations.md | Adds breaking change note describing the expanded *Operation coverage. |
| csharp/downgrades/d13c4c187d7318fd2b8f35c7e8d7f4dc26be68b1/upgrade.properties | Adds downgrade metadata corresponding to the operations refactor. |
| csharp/downgrades/d13c4c187d7318fd2b8f35c7e8d7f4dc26be68b1/semmlecode.csharp.dbscheme | Adds downgrade dbscheme snapshot/scaffolding. |
| csharp/downgrades/d13c4c187d7318fd2b8f35c7e8d7f4dc26be68b1/old.dbscheme | Adds “old” dbscheme snapshot for downgrade comparisons. |
Copilot's findings
- Files reviewed: 21/21 changed files
- Comments generated: 2
| /** | ||
| * A binary logical operation. Either a logical 'and' (`LogicalAndExpr`), | ||
| * a logical 'or' (`LogicalAndExpr`), or a null-coalescing operation | ||
| * (`NullCoalescingExpr`). | ||
| * (`NullCoalescingOperation`). | ||
| */ |
| /** | ||
| * An multiplication assignment operation, for example `x *= y`. | ||
| * An multiplication assignment expression, for example `x *= y`. | ||
| */ | ||
| class AssignMulExpr extends AssignArithmeticOperation, MulOperation, @assign_mul_expr { | ||
| class AssignMulExpr extends AssignArithmeticExpr, MulOperation, @assign_mul_expr { |
In this PR we streamline the implementation for operations - they now include assignments as well.
That is,
BinaryArithmeticOperation,BinaryBitwiseOperationandBinaryLogicalOperationnow include compound assignments (e.g.BinaryArithmeticOperationnow includea += b).Some queries and tests have been re-written slightly and in other places (like guards and data flow, the operations now include compound assignment expressions as well).